package com.haojiang.mh.utils;

/**
 * CRC
 * <p>
 * Created by ZapFive on 2019-05-27.
 * <p>
 * wuzhuang@mirahome.me
 */
public class CrcUtil {
    public static byte calcCheck(byte[] ptr, int len) {
        byte i;
        byte crc = 0;
        int j = 0;
        while (len-- != 0) {
            for (i = 1; i != 0; i *= 2) {
                if ((crc & 1) != 0) {
                    crc >>= 1;
                    crc &= 0x7F;
                    crc ^= 0x8C;
                } else {
                    crc >>= 1;
                    crc &= 0x7F;
                }
                if ((ptr[j] & i) != 0) {
                    crc ^= 0x8C;
                }
            }
            j++;
        }
        return crc;
    }
}
